package net.cn_su.sharpeyes.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.TextView;

import net.cn_su.sharpeyes.R;
import net.cn_su.sharpeyes.beans.MessageInfo;
import net.cn_su.sharpeyes.utils.DateTool;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.Fullscreen;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

/**
 * 报政务详情
 */
@EActivity(R.layout.activity_zenwu_detail)
@Fullscreen
public class MessageDetailActivity extends AppCompatActivity {


    @ViewById
    protected WebView web;
    @ViewById(R.id.textView2)
    protected TextView textView_name;
    @ViewById(R.id.textView_time)
    protected TextView textView_time;

    @ViewById
    protected ProgressBar progressBar;
    @Extra
    MessageInfo info;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    @AfterViews
    protected void initData() {

        textView_name.setText(info.getTitle());
        textView_time.setText(DateTool.timesToStrTime(info.getCreated_at() + "", "yyyy-MM-dd"));


        web.getSettings().setJavaScriptEnabled(true);
        //设置可以访问文件
        web.getSettings().setAllowFileAccess(true);

        web.loadDataWithBaseURL(null, info.getContent(), "text/html", "utf-8", null);

    }


    /**
     * 返回
     */
    @Click(R.id.btn_back)
    protected void btnFinish() {
        finish();
    }


    /**
     * 隐藏进度条
     */
    @UiThread
    protected void hideProgressBar() {
        progressBar.setVisibility(View.GONE);
    }

    /**
     * 显示进度条
     */
    @UiThread
    protected void showProgressBar() {
        progressBar.setVisibility(View.VISIBLE);
    }
}
